home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Browsers, Managers & Extensions
/
Firefox Backup Extension 6.0.3
/
chrome
/
febe.jar
/
content
/
febeUDBu.js
< prev
next >
Wrap
Text File
|
2008-08-06
|
16KB
|
443 lines
// author: Chuck Baker
// contact: firefox@customsoftwareconsult.com
// FEBE User-defined backup routines
var febeUDBuList = [];
var febeUDBuAction = new Number; // 1=New, 2=Edit, 3=Delete
var febeUDBuTrxPending = new Boolean(false);
function febeUDBuObj(Label, Type, Description, Path, Include){
this.Label = Label;
this.Type = Type;
this.Description = Description;
this.Path = Path;
this.Include = Include;
return true;
}//febeUDBuObj
function febeLoadUDBu(){
var febeUDBuWin = window.openDialog("chrome://febe/content/febeUDBu.xul", febeMsg[147], "chrome,alwaysRaised,centerscreen,resizable");
return true;
}//febeLoadUDBu()
function febeNewUDBu(){
febeUDBuDisableAll();
document.getElementById("febeUDBuCaption").value = febeMsg[136];
febeUDBuAction = 1;
febeUDBuEnableNew();
febeUDBuStatusMsg("");
return true;
}//febeNewUDBu()
function febeEditUDBu(){
febeUDBuDisableAll();
document.getElementById("febeUDBuCaption").value = febeMsg[137];
febeUDBuAction = 2;
febeUDBuPopulateListbox();
febeUDBuStatusMsg("");
return true;
}//febeEditUDBu()
function febeDeleteUDBu(){
febeUDBuDisableAll();
document.getElementById("febeUDBuCaption").value = febeMsg[138];
febeUDBuAction = 3;
febeUDBuPopulateListbox();
febeUDBuStatusMsg("");
return true;
}//febeDeleteUDBu()
function febeSelUDBu(){
var dd = document.getElementById("febeUDBuType");
if(dd.selectedIndex == -1){
var tmp = febeMsg[165];
febeAlert(tmp);
return false;
}//if
var type = dd.selectedIndex;
switch(type){
case 0: // File
febeSelUDBuFile();
break;
case 1: // Folder
febeSelUDBuFolder();
break;
}//switch
return true;
}//febeSelUDBu(){
function febeSelUDBuFile(){
// Select a file to backup
var fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
fp.init(window, febeMsg[133], Ci.nsIFilePicker.modeOpen);
fp.appendFilters(Ci.nsIFilePicker.filterAll);
// Set the default directory to the current profile directory
febeProfDir = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties).get("ProfD", Ci.nsIFile);
fp.displayDirectory = febeProfDir;
var rv = fp.show();
if (rv == Ci.nsIFilePicker.returnOK){
rv = fp.file;
document.getElementById("febeUDBuSource").value = rv.path;
return true;
}//if
return false;
}//febeSelUDBuFile()
function febeSelUDBuFolder(){
// Select a folder to backup
var fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
fp.init(window, febeMsg[159], Ci.nsIFilePicker.modeGetFolder);
fp.appendFilters(Ci.nsIFilePicker.filterAll | Ci.nsIFilePicker.filterText);
// Set the default directory to the current profile directory
febeProfDir = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties).get("ProfD", Ci.nsIFile);
fp.displayDirectory = febeProfDir;
var rv = fp.show();
if (rv == Ci.nsIFilePicker.returnOK){
rv = fp.file;
document.getElementById("febeUDBuSource").value = rv.path;
return true;
}//if
return false;
}//febeSelUDBuFolder()
function febeUDBuInit(){
febeSetMsgs();
// Get data from file - create template if needed
febeDataFile = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties).get("ProfD", Ci.nsIFile);
febeDataFile.append(FEBEDATAFILE);
var JSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
if(!febeDataFile.exists()){
// Create the template
var dflt = new febeUDBuObj();
dflt.Label = febeMsg[182];
dflt.Type = 0;
dflt.Description = febeMsg[181];
dflt.Path = febeDataFile.path.replace(/\\/g,"\\");
dflt.Include = true;
var fos = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
fos.init(febeDataFile, 0x02 | 0x08 | 0x20, 0755, 0); // write, create, truncate
var cos = Cc["@mozilla.org/intl/converter-output-stream;1"].createInstance(Ci.nsIConverterOutputStream);
cos.init(fos, "UTF-8", 0, 0x0000);
var jstr = JSON.encode(dflt);
cos.writeString(jstr+"\n");
cos.close();
}//if
// Read the data
var dFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
dFile.initWithPath(febeDataFile.path);
// open an input stream from file
var fis = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream);
fis.init(dFile, 0x01, 0444, 0);
fis.QueryInterface(Ci.nsILineInputStream);
var cis = Cc["@mozilla.org/intl/converter-input-stream;1"].createInstance(Ci.nsIConverterInputStream);
cis.init(fis,"UTF-8", 0, 0x0000);
var lis = cis.QueryInterface(Ci.nsIUnicharLineInputStream);
// read lines into array and parse into individual fields
febeUDBuList = [];
var line = {}, hasmore, cnt;
cnt = 0; // Count of UDBU items
do {
hasmore = lis.readLine(line);
if(line.value.length == 0){break;}
var febeUDBuItem = JSON.decode(line.value);
febeUDBuList[febeUDBuItem.Label] = febeUDBuItem;
cnt += 1;
} while(hasmore);
cis.close();
fis.close();
try {
document.documentElement.getButton("extra2").disabled = true;
febeUDBuStatusMsg("");
}catch(e){;;}
if(cnt == 0){return false;}
return true;
}//febeUDBuInit()
function febeUDBuWrite(obj){
var fos = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
fos.init(dFile, 0x02 | 0x08 | 0x20, 0755, 0); // write, create, truncate
var cos = Cc["@mozilla.org/intl/converter-output-stream;1"].createInstance(Ci.nsIConverterOutputStream);
cos.init(fos, "UTF-8", 0, 0x0000);
var jstr = JSON.encode(obj);
cos.writeString(jstr+"\n");
}//febeUDBuWrite()
function febeUDBuWrite(){
febeDataFile = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties).get("ProfD", Ci.nsIFile);
febeDataFile.append(FEBEDATAFILE);
var JSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
var fos = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
fos.init(febeDataFile, 0x02 | 0x08 | 0x20, 0755, 0); // write, create, truncate
var cos = Cc["@mozilla.org/intl/converter-output-stream;1"].createInstance(Ci.nsIConverterOutputStream);
cos.init(fos, "UTF-8", 0, 0x0000);
for(var i in febeUDBuList){
var jstr = JSON.encode(febeUDBuList[i]);
cos.writeString(jstr+"\n");
}//for
cos.close();
return true;
}//febeUDBuWrite()
function febeUDBuDisableAll(){
document.getElementById("febeUDBuCaption").value = febeMsg[134];
document.getElementById("febeUDBuList").removeAllItems();
document.getElementById("febeUDBuList").setAttribute("label",febeMsg[135]);
document.getElementById("febeUDBuList").disabled = true;
document.getElementById("febeUDBuLabelID").disabled = true;
document.getElementById("febeUDBuLabel").disabled = true;
document.getElementById("febeUDBuTypeID").disabled = true;
document.getElementById("febeUDBuType").disabled = true;
document.getElementById("febeUDBuDescID").disabled = true;
document.getElementById("febeUDBuDesc").disabled = true;
document.getElementById("febeUDBuSourceID").disabled = true;
document.getElementById("febeUDBuSource").disabled = true;
document.getElementById("febeUDBuBrowseBtn").disabled = true;
document.getElementById("febeIncludeInBu_id").disabled = true;
document.getElementById("febeUDBuSubmitBtn").disabled = true;
document.getElementById("febeUDBuLabel").value = "";
document.getElementById("febeUDBuDesc").value = "";
document.getElementById("febeUDBuSource").value = "";
document.getElementById("febeIncludeInBu_id").checked = false;
febeUDBuStatusMsg("");
return true;
}//febeUDBuDisableAll()
function febeUDBuEnableNew(){
document.getElementById("febeUDBuCaption").value = febeMsg[136];
document.getElementById("febeUDBuList").setAttribute("label",febeMsg[135]);
document.getElementById("febeUDBuList").disabled = true;
document.getElementById("febeUDBuLabelID").disabled = false;
document.getElementById("febeUDBuLabel").disabled = false;
document.getElementById("febeUDBuTypeID").disabled = false;
document.getElementById("febeUDBuType").disabled = false;
document.getElementById("febeUDBuDescID").disabled = false;
document.getElementById("febeUDBuDesc").disabled = false;
document.getElementById("febeUDBuSourceID").disabled = false;
document.getElementById("febeUDBuSource").disabled = false;
document.getElementById("febeUDBuBrowseBtn").disabled = false;
document.getElementById("febeIncludeInBu_id").disabled = false;
document.getElementById("febeUDBuSubmitBtn").disabled = false;
document.getElementById("febeUDBuLabel").value = "";
document.getElementById("febeUDBuDesc").value = "";
document.getElementById("febeUDBuSource").value = "";
document.getElementById("febeIncludeInBu_id").checked = false;
febeUDBuStatusMsg("");
return true;
}//febeUDBuEnableNew()
function febeUDBuEnableEdit(){
//document.getElementById("febeUDBuList").removeAllItems();
document.getElementById("febeUDBuList").setAttribute("label",febeMsg[135]);
document.getElementById("febeUDBuList").disabled = false;
document.getElementById("febeUDBuLabelID").disabled = false;
document.getElementById("febeUDBuLabel").disabled = true;
document.getElementById("febeUDBuTypeID").disabled = false;
document.getElementById("febeUDBuType").disabled = false;
document.getElementById("febeUDBuDescID").disabled = false;
document.getElementById("febeUDBuDesc").disabled = false;
document.getElementById("febeUDBuSourceID").disabled = false;
document.getElementById("febeUDBuSource").disabled = false;
document.getElementById("febeUDBuBrowseBtn").disabled = false;
document.getElementById("febeIncludeInBu_id").disabled = false;
document.getElementById("febeUDBuSubmitBtn").disabled = false;
document.getElementById("febeUDBuLabel").value = "";
document.getElementById("febeUDBuDesc").value = "";
document.getElementById("febeUDBuSource").value = "";
document.getElementById("febeIncludeInBu_id").checked = false;
febeUDBuStatusMsg("");
return true;
}//febeUDBuEnableEdit()
function febeUDBuEnableDelete(){
//document.getElementById("febeUDBuCaption").value = febeMsg[138];
document.getElementById("febeUDBuList").removeAllItems();
document.getElementById("febeUDBuList").setAttribute("label",febeMsg[135]);
document.getElementById("febeUDBuList").disabled = false;
document.getElementById("febeUDBuLabelID").disabled = false;
document.getElementById("febeUDBuLabel").disabled = true;
document.getElementById("febeUDBuTypeID").disabled = true;
document.getElementById("febeUDBuType").disabled = true;
document.getElementById("febeUDBuDescID").disabled = false;
document.getElementById("febeUDBuDesc").disabled = true;
document.getElementById("febeUDBuSourceID").disabled = false;
document.getElementById("febeUDBuSource").disabled = true;
document.getElementById("febeUDBuBrowseBtn").disabled = true;
document.getElementById("febeIncludeInBu_id").disabled = true;
document.getElementById("febeUDBuSubmitBtn").disabled = false;
document.getElementById("febeUDBuLabel").value = "";
document.getElementById("febeUDBuDesc").value = "";
document.getElementById("febeUDBuSource").value = "";
document.getElementById("febeIncludeInBu_id").checked = false;
febeUDBuStatusMsg("");
return true;
}//febeUDBuEnableDelete()
function febeUDBuOK(){
febeUDBuWrite();
febeUDBuStatusMsg(febeMsg[149]);
return true;
}//febeUDBuOK()
function febeUDBuCancel(){
if(febeUDBuTrxPending == true){
var style = "<style>color: red; font-weight: bold; font-size: 20px;</style>"
var tmp = style+febeMsg[139]+"\n";
tmp += style+febeMsg[140]+"\n\n";
tmp += febeMsg[141];
return febeConfirm(tmp);
}//if
return true;
}//febeUDBuCancel()
function febeUDBuSubmit(){
var febeUDBuItem = new febeUDBuObj;
febeUDBuItem.Label = document.getElementById("febeUDBuLabel").value;
febeUDBuItem.Type = document.getElementById("febeUDBuType").selectedIndex;
febeUDBuItem.Description = document.getElementById("febeUDBuDesc").value;
febeUDBuItem.Path = document.getElementById("febeUDBuSource").value;
febeUDBuItem.Include = document.getElementById("febeIncludeInBu_id").checked;
var key = febeUDBuItem.Label;
var action;
switch(febeUDBuAction){
case 1: // New
action = febeMsg[92];
if(febeUDBuItem.Label == ""){
febeAlert(febeMsg[142]);
return false;
}//if
if(febeUDBuItem.Type == -1){
febeAlert(febeMsg[160]);
return false;
}//if
if(febeUDBuItem.Description == ""){
febeAlert(febeMsg[143]);
return false;
}//if
if(febeUDBuItem.Path == ""){
febeAlert(febeMsg[144]);
return false;
}//if
// See if label already exists
for(var tmp in febeUDBuList){
if(tmp == key){
febeAlert(febeMsg[145].replace("%key%",key));
return false;
}//if
}//for
febeUDBuList[key] = febeUDBuItem;
break;
case 2: // Edit
action = febeMsg[93];
febeUDBuList[key] = febeUDBuItem;
break;
case 3: // Delete
action = febeMsg[94];
delete febeUDBuList[key];
break;
default:// WTF??
;
}//switch
febeUDBuTrxPending = true;
document.documentElement.getButton("extra2").disabled = false;
febeUDBuDisableAll();
febeUDBuStatusMsg(febeMsg[146].replace("%ACTION%",action));
return true;
}//febeUDBuSubmit()
function febeUDBuPopulateListbox(){
// Clear existing items
var submenu = document.getElementById("febeUDBuList");
var children = submenu.childNodes;
var n = children.length;
for (var i = 0; i < n; i++) {
submenu.removeChild(children[0]);
}
for(var i in febeUDBuList){
document.getElementById("febeUDBuList").appendItem(febeUDBuList[i].Label,febeUDBuList[i].Label);
}//for
document.getElementById("febeUDBuList").disabled = false;
return true;
}//febeUDBuPopulateListbox()
function febeUDBuDisplayData(){
var key = document.getElementById("febeUDBuList").selectedItem.value;
switch(febeUDBuAction){
case 2:
febeUDBuEnableEdit();
break;
case 3:
febeUDBuEnableDelete();
break;
}//switch
document.getElementById("febeUDBuLabel").value = febeUDBuList[key].Label;
document.getElementById("febeUDBuType").selectedIndex = febeUDBuList[key].Type;
document.getElementById("febeUDBuDesc").value = febeUDBuList[key].Description;
document.getElementById("febeUDBuSource").value = febeUDBuList[key].Path;
document.getElementById("febeIncludeInBu_id").setAttribute("checked",febeUDBuList[key].Include);
return true;
}//febeUDBuDisplayData()
function febe_fillUDBUmenu(element){
// Populate the restore UDBU submenu
// Clear existing items
var submenu = document.getElementById(element);
var children = submenu.childNodes;
var n = children.length;
for (var i = 0; i < n; i++) {
submenu.removeChild(children[0]);
}
febeUDBuInit();
for(var i in febeUDBuList){
var oncommand = "febeRestoreUDBU('"+i+"');";
var aMenuItem=document.createElement("menuitem");
aMenuItem.setAttribute( "label" , febeUDBuList[i].Label);
aMenuItem.setAttribute( "oncommand" , oncommand);
aMenuItem.setAttribute( "tooltiptext" , febeMsg[170]+" "+febeUDBuList[i].Description);
document.getElementById(element).appendChild(aMenuItem);
}//for
return true;
}//febe_fillUDBUmenu()
function febeResetUDBu(){
var style = "<style>color: red; font-weight: bold; font-size: 14px;</style>"
var tmp = style+febeMsg[174]+"\n\n";
tmp += febeMsg[175];
if(!febeConfirm(tmp)){return true;};
var febeDataFile = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("ProfD", Ci.nsIFile);
febeDataFile.append(FEBEDATAFILE);
if(febeDataFile.exists()){febeDataFile.remove(false);}
febeUDBuList = [];
febeUDBuInit();
febeUDBuPopulateListbox();
febeUDBuDisableAll();
febeAlert(febeMsg[176]);
return true;
}//febeResetUDBu()
function febeUDBuStatusMsg(msg){
var d = document.getElementById("febeUDBustatusText");
if(d){
d.value = msg;
//sizeToContent();
}//if
return true;
}//febeUDBuStatusMsg()
//febeAlert("febeDBM.js loaded");